import QtQuick 2.6
import QtQuick.Layouts 1.2

import "../../Base/UiBase"
import "../../Base/Config"

import Data 1.0

import Cpp.Type 1.0

import "../../FallView" as FallView
import "../../Evaluation/Multi/Post" as EVPost

Rectangle {
    id: root

    property string target: "all" // candidates: "all"

    color: Color.background

    MouseArea {
        z: -1
        anchors.fill: parent
    }

    ColumnLayout {
        anchors.fill: parent
        spacing: 0

        // header
        Rectangle {
            Layout.fillWidth: true
            Layout.preferredHeight: 96 * Size.ratio
            color: Color.foreground

            // back button
            ImageButton {
                width: 80 * Size.ratio
                height: 96 * Size.ratio
                anchors.left: parent.left
                anchors.verticalCenter: parent.verticalCenter
                source: "../../../resources/comment/fanhiu01.svg"

                onClicked: root.visible = false
            } // end back button

            Text {
                anchors.centerIn: parent
                text: qsTr("我的作品")
                color: Color.input
                font.pixelSize: Size.titleFont
            }
            BottomDivider {
            }
        } // end header

        // switcher
        Rectangle {
            property string place: "left"
            Layout.fillWidth: true
            Layout.preferredHeight: 96 * Size.ratio
            color: Color.foreground
            MouseArea {
                onClicked: root.page = "commentFromMe"
                anchors.fill: parent

                Text {
                    x: 40 * Size.ratio
                    anchors.verticalCenter: parent.verticalCenter
                    font.pixelSize: Size.font32
                    color: Color.virtualInput
                    text: qsTr("对谁可见")
                }
                Text {
                    function trTarget(target) {
                        if (target === "all")
                            return qsTr("所有人")
                        return "???"
                    }
                    anchors.right: parent.right
                    anchors.rightMargin: 40 * Size.ratio
                    anchors.verticalCenter: parent.verticalCenter
                    font.pixelSize: Size.font32
                    color: Color.virtualInput
                    text: trTarget(root.target)
                }
            }
        }

        // end switcher
        Item {
            Layout.fillWidth: true
            Layout.preferredHeight: 20 * Size.ratio
        }

        // body
        FallView.FallView {
            Layout.fillWidth: true
            Layout.fillHeight: true
            z: -1

            delegate: EVPost.Post {
                width: parent.width
                name: model.username
                headSource: model.head
                subject: model.subject
                time: model.postTime
                province: model.province
                city: model.city
                imageCount: model.imageCount
                imageSource: model.image
                audioSource: model.audio
                comment: model.comment
                type: model.type
            }
            model: listmodel
        } // end body
    }
    ListModel {
        id: listmodel
        Component.onCompleted: {
            listmodel.append({
                                 type: "钢琴  ",
                                 username: "欢乐的0403",
                                 head: "../../../resources/tests/touxiang02.svg",
                                 subject: Subject.Music,
                                 postTime: new Date(),
                                 province: qsTr("广西"),
                                 city: qsTr("来宾"),
                                 audio: "../../../resources/tests/钢琴曲 - Summer.mp3",
                                 imageCount: 0,
                                 image: "",
                                 comment: "asdfasdf!@#!@#!@########!!!!!!!!!!!!!!!!!!"
                             })
            listmodel.append({
                                 type: "就是画画  ",
                                 username: "欢乐的0403",
                                 head: "../../../resources/tests/touxiang02.svg",
                                 subject: Subject.Paint,
                                 postTime: new Date(),
                                 province: qsTr("广西"),
                                 city: qsTr("来宾"),
                                 imageCount: 1,
                                 image: "../../../resources/tests/121025539394.jpg",
                                 comment: "asdfasdf!@#!@#!@########!!!!!!!!!!!!!!!!!!"
                             })
            listmodel.append({
                                 type: "就是插图  ",
                                 username: "欢乐的0403",
                                 head: "../../../resources/tests/touxiang02.svg",
                                 subject: Subject.Pe,
                                 postTime: new Date(),
                                 province: qsTr("广西"),
                                 city: qsTr("来宾"),
                                 imageCount: 1,
                                 image: "../../../resources/tests/121025539394.jpg",
                                 comment: "asdfasdf!@#!@#!@########!!!!!!!!!!!!!!!!!!"
                             })
        }
    }
}
